package com.gxa.admin.controller;

import com.gxa.admin.pojo.dto.OrderListDto;
import com.gxa.admin.service.OrderListService;
import com.gxa.admin.utils.QueryResult;
import com.gxa.core.result.MessageCode;
import com.gxa.core.result.Result;
import com.gxa.core.result.ResultUtils;
import com.gxa.service.OrderListRpcDto;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：lizhijun
 * @Package：{PROJECT_NAME}
 * @name：{DATE} {NAME}
 */
@Api(tags = "订单接口")
@RestController
@RequestMapping("/admin/orderList")
@Slf4j
public class OrderListController {
    @Autowired
     private OrderListService orderListService;

    @PostMapping("/addOrder")
    public Result addOrder(OrderListRpcDto orderListRpcDto) {
        log.info("添加订单{}",orderListRpcDto);
        //远程调用
        return ResultUtils.buildSuccess( this.orderListService.addOrderList(orderListRpcDto));
    }
    @PostMapping( "/showBackOrdersAll")
    public Result getAllOrderList(@RequestBody OrderListDto orderListDto) {
        QueryResult queryResult = this.orderListService.getOrderList(orderListDto);
        if (queryResult != null) {
            return ResultUtils.buildSuccess(queryResult.getCount(), queryResult.getData());
        }
        return ResultUtils.buildFail(MessageCode.UN_KNOW_EXCEPTION);
    }
    @GetMapping("/alterOrder")
    public Result acceptOrder(OrderListDto orderListDto){
       Result result = this.orderListService.acceptOrder(orderListDto);
        if (result != null) {
            return ResultUtils.buildSuccess(result.getCount(), result.getData());
        }
        return ResultUtils.buildFail(MessageCode.UN_KNOW_EXCEPTION);
    }
    @GetMapping("/deleteOrder")
    public Result deleteOrder(OrderListDto orderListDto){
        orderListDto.setStatus("已删除");
        Result result = this.orderListService.acceptOrder(orderListDto);
        if (result != null) {
            return ResultUtils.buildSuccess(result.getCount(), result.getData());
        }
        return ResultUtils.buildFail(MessageCode.UN_KNOW_EXCEPTION);
    }
}
